package com.jianan.mis.util.ui.table;

import java.util.Map;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.TableColumn;


public class TableCreator {

	public static TableColumn createTableColumn(TableViewer viewer, int style,
			String text, String tooltip, int width, Map<String, Object> data) {
		TableColumn column = new TableColumn(viewer.getTable(), style);
		column.setText(text);
		column.setToolTipText(tooltip);
		column.setWidth(width);
		if (data != null) {
			for (String key : data.keySet()) {
				column.setData(key, data.get(key));
			}
		}
		return column;
	}

	public static TableSortSelectionListener createSortedTableColumn(
			TableViewer viewer, int style, String text, String tooltip,
			int width, AbstractInvertableTableSorter sorter,
			int initialDirection, boolean keepDirection,
			Map<String, Object> data) {

		return new TableSortSelectionListener(viewer, createTableColumn(viewer,
				style, text, tooltip, width, data), sorter, initialDirection,
				keepDirection);
	}
}
